import Curd from './base/curd'
import http from './base/axios'

var curd = new Curd("file");

curd.view = "/api/file/view/"
curd.upload = "/api/file/upload/"
curd.delete = "/api/file/delete/"

curd.queryByBookId = (bookId) => {
	return http.get(curd.root, {
		params: {
			bookId: bookId
		}
	}).then(resp => resp.data);
}

curd.upload = (data) => {
	let param = new FormData(); // 创建form对象
	param.append('localFile', data); // 将文件存入file下面
	let config = {
		headers: {
			'Content-Type': 'multipart/form-data'
		}
	}
	return http.post(curd.url.upload, param, config)
		.then(resp => resp.data).catch(err => {
			console.log(err)
		})
}

export default curd;
